package kr.co.redcircle.service.oAuth;

import java.util.Scanner;

import kr.co.redcircle.service.oAuth.api.naver.me2day.Me2dayApi;

import org.scribe.builder.ServiceBuilder;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;

public class Me2dayTestCase
{
  private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1/statuses/update.json";
  
  public static void main(String[] args)
  {

		String apiKey = "19757141d86925ee472a54ffe64645f8";
	    String apiSecret = "none";

	    OAuthService service = new ServiceBuilder().
	    		provider(Me2dayApi.class).
	    		apiKey(apiKey).
	    		apiSecret(apiSecret).
	    		build();
    
	    Scanner in = new Scanner(System.in);

	    String authorizationUrl = service.getAuthorizationUrl(null);
	    System.out.println(authorizationUrl);
	    System.out.print(">>");
	    Verifier verifier = new Verifier(in.nextLine());
	    System.out.println();
    
	    Token accessToken = service.getAccessToken(null, verifier);

	    OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
	    service.signRequest(accessToken, request);
	    Response response = request.send();
	    System.out.println(response.getCode());
	    System.out.println(response.getBody());

  }

}